<?php
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/taobao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/qq/inc.php");
//所有的参数
$g_cgival 	= array();
//存储中间数据 非输出数据 可以不用
$g_pro	 	= array();
//要显示的数据 输出数据
$g_show 	= array();

function check_cgi_pro()
{		
	global $g_cgival, $g_pro, $g_show, $config;
	
	cgi::both($g_cgival["p"], "p", "");
	$g_cgival["p"] = intval($g_cgival["p"]);
	
	if($g_cgival["p"] < 1) $g_cgival["p"]=1;
	
	cgi::both($g_cgival["topic_id"], "topic_id", "");
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["show_type"], "show_type", "");
	$g_cgival["show_type"] = intval($g_cgival["show_type"]);
	
	cgi::both($g_cgival["uid"], "uid", "");
}


function get_data()
{
	global $g_cgival, $g_pro, $g_show, $config;
	$g_show["channel"] = "video";
	$pcount = $g_cgival["pcount"] = 20;
	$p = $g_cgival["p"];
	$topic_id = $g_cgival["topic_id"] = $config['current_site_id'];
	$show_type = $g_cgival["show_type"];
	$status = 1;
	$g_show["uid"] = $uid = $g_cgival["uid"];
	$order = $g_cgival["order"];
	$db_mblog_video_content = new db_mblog_video_content();
	
	$db_mblog_video_content = new db_mblog_video_content();

	$list = $db_mblog_video_content->get_mblog_video_list_by_topic($p,$pcount,$topic_id,$uid);
	$count = $db_mblog_video_content->get_mblog_video_count_by_topic($topic_id,$uid);
	
	foreach($list as $key => $value)
	{
		$list[$key]["pic"] = $value["video_pic"];
		
	}
		

	
	//如果在主站
	if(!$topic_id)
	{
		foreach($list as $key => $value)
		{
			$list[$key]["domain_url"] = $config["domain_url"][$value["topic_id"]]? "http://{$config["domain_url"][$value["topic_id"]]}" :"";
		}
	
	}
	
	
	$g_show["count"] = $count;
	$g_show["list"] = $list;
	
	if($uid)
	{
		$Pages = new Pages($count,$p,$pcount);
		$g_show["page_bar"] = $Pages->getLinks_static("/video/index_replacepage_{$uid}.html",8);
	}
	else
	{
		$Pages = new Pages($count,$p,$pcount);
		$g_show["page_bar"] = $Pages->getLinks_static("/video/index_replacepage.html",8);
	
	}

	
	$g_show["page_title"] = $page_title;
	$g_show["order"] = $order;
	$g_show["topic_id"] = $topic_id;
	$g_show["show_type"] = $show_type;
	$g_show["pubu_show_type"] = "video";
	
	
	$prev_page = ($p-1);
	if($prev_page > 0)
	{
		$g_show["prev"] = 	"/video/index_{$prev_page}.html";
	}
	
	$next_page = $p+1;
	$total_page = ceil($count/$pcount);
	if($next_page <= $total_page)
	{
		$g_show["next"] = 	"/video/index_{$next_page}.html";
		
	}
	
	
	$db_taobao_goods_item = new db_taobao_goods_item();
	$tao_tuijian = $db_taobao_goods_item->get_taobao_list_by_site_id(1,10);
	
	$g_show["tao_tuijian"] = $tao_tuijian;
	
	
	if($uid)
	{
		$db_qq_user_info = new db_qq_user_info();
		$item_user_info = $db_qq_user_info->get_qq_user_info_item_by_uid($uid);
		$title_desc = $item_user_info["user_nickname"]."的视频分享_";
	}
	$current_site_name = $config["current_site_name"];
	$g_show["page_keywords"]  = "{$item_user_info["user_nickname"]},{$title_desc},{$current_site_name}视频,{$current_site_name}分享,{$current_site_name}玩家视频,{$current_site_name}精彩视频,{$current_site_name}视频大全,{$current_site_name}视频分享";
	$g_show["page_desc"]  = "{$title_desc}{$current_site_name}视频_游戏美图_最有意思的游戏玩家分享平台";
	$g_show["page_title"] = "{$title_desc}{$current_site_name}视频_游戏美图_最有意思的游戏玩家分享平台";
	
	
	
	$top_list = $db_mblog_video_content->get_mblog_video_content_num_top(5,$topic_id);
	
	$g_show["top_list"] = $top_list;
	
}

try {
	$g_show['error'] = 0;
	$g_show['errmsg'] = "";
	check_cgi_pro();
	get_data();
	
} catch (Exception $e) {
	$g_show['error'] = 1;
	$g_show['errmsg'] = $e->getMessage();
}

show_pro();


exit;

function show_pro()
{
	global $g_cgival, $g_pro, $g_show, $config;

	$smarty = p_get_smarty();	
	$smarty->assign("g_show", $g_show);
	if (isset($_GET["debug"]))
	{
		print_r($g_show);
	}
	$smarty->display("video/index.html");
	
	unset($g_cgival);
	unset($g_pro);
	unset($g_show);
	unset($config);
	
}

